package com.itheima.controller;


import com.itheima.common.PageBean;
import com.itheima.common.R;
import com.itheima.dto.ClazzDto;
import com.itheima.pojo.Clazz;
import com.itheima.service.ClazzService;
import com.itheima.vo.ClazzVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 班级表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-07-28
 */
@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    @GetMapping
    public R list(  ClazzDto clazzDto ) {
        PageBean pageBean = clazzService.list(clazzDto);


        return R.ok(pageBean);

    }
    @PostMapping
    public R add(@RequestBody Clazz clazz) {

        clazzService.add(clazz);
        return R.ok();
    }
    @GetMapping("/{id}")
    public R get(@PathVariable("id") Integer id) {
        Clazz clazz =  clazzService.getById(id);
        return R.ok(clazz);
    }
    @PutMapping
    public R update(@RequestBody Clazz clazz) {
        clazzService.updateById(clazz);
        return R.ok();
    }
    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id") Integer id) {
        clazzService.deleteById(id);
        return R.ok();
    }
    @GetMapping("list")
    public R list2() {
        List<Clazz> list= clazzService.listall();
        log.info("clazzVo:{}", list);
        return R.ok(list);
    }
}
